package connect;

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class Connect {
	public Connect() {
	}

	public Connection getConnection() {
		Connection connection = null;
		try {
			Context envCtx = (Context) 
						new InitialContext().lookup("java:comp/env");
			DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");
			connection = ds.getConnection();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
		return connection;
	}

	public static void main(String[] args) {
		Connect c = new Connect();
		System.out.println(c.getConnection());
	}
}
